"use strict";
var mongoose = require("mongoose");
var User = require("./user");
;
exports.Schema = new mongoose.Schema({
    // user: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
    // user: User.Schema,
    user: {
        _id: { type: mongoose.Schema.Types.ObjectId, ref: "User" },
        skin: Number,
        name: String,
        isMale: Boolean,
        role: String,
        iconPath: String,
        level: Number,
        roleRecords: [{
                role: String,
                wins: Number,
                loses: Number,
            }],
        isAnchor: Boolean,
    },
    role: { type: String, default: "" },
    camp: { type: String, default: "" },
    isRobot: { type: Boolean, default: false },
    isReady: { type: Boolean, default: false },
    isOnline: { type: Boolean, default: true },
    isVerified: { type: Boolean, default: false },
    isSpeaking: { type: Boolean, default: false },
    // isAlive: Boolean, // 是否活著
    deadInfo: {
        state: { type: Number, default: 0 },
        day: { type: Number, default: 0 },
        isOnline: { type: Boolean, default: true },
    },
    leaderState: { type: Number, default: 0 },
    isLover: { type: Boolean, default: false },
    selectablePlayers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Player" }],
    selectedPlayers: [{ type: mongoose.Schema.Types.ObjectId, ref: "Player" }],
    flags: [String],
    roleFlags: [String],
    memberId: String,
    isConfirmSkip: Boolean,
});
exports.Model = mongoose.model("Player", exports.Schema);
// export function isAlive (player: Document, room: Room.Document): boolean {
// 	return !room.deadPlayers.find(dp => dp.player.equals(player._id));
// }
function create(user, isRobot, oldPlayer) {
    if (oldPlayer === void 0) { oldPlayer = null; }
    var player = new exports.Model();
    player.user = user;
    player.user.name = User.getName(user);
    player.user.isMale = User.getIsMale(user);
    player.user.iconPath = User.getIconPath(user);
    player.user.isAnchor = user.isAnchor;
    player.isRobot = isRobot;
    player.isReady = isRobot;
    if (oldPlayer) {
        player.memberId = oldPlayer.memberId;
    }
    return player;
}
exports.create = create;
